/**
 * 表单逻辑
 */
import Vue from 'vue'
import { Toast } from 'vant'
import _http from '../../../api/http'
import dateUtil from '../common/dateUtil'
import formElement from './formElement'
import { checkIdcard } from '../../../assets/js/common/checkIdcard'
Vue.use(Toast)
const regName = /^[\u4e00-\u9fa5]+(·[\u4e00-\u9fa5]+)*$/
const regTelephone = /^\d{3,4}-\d{6,8}$/
const regMobilephone = /^[1][2-9][0-9]{9}$/
let token
let idcard
let userRealName
let disableSurvey
let personInfo
let historyData
let lowSecurity
let dbc
let lifeSubsidy
let severeSubsidy
let element
let dBarrierFree
let dJob
let dJobHelp
let dHouseAssist
let dSchool
let dShortHelp
const sessionStorage = window.sessionStorage
function initData (vue) {
  token = decodeURIComponent(vue.$route.query.token)
  // 根据身份证号获取残疾人的采集相关信息
  // 参数身份证号
  idcard = vue.$route.query.idcard
  // 用户姓名
  userRealName = vue.$route.query.userRealName
  sessionStorage.setItem('token', token)
  sessionStorage.setItem('userRealName', userRealName)
  // 临时本地json请求
  _http
    .post(
      '/disableSurvey/surveyInfo/' + idcard,
      {},
      {
        'Content-Type': 'application/x-www-form-urlencoded'
      }
    )
    .then(result => {
      if (result && result.code == 200) {
        vue.surveyInfo = Object.assign({}, vue.surveyInfo, result.data)
        if (vue.surveyInfo.disableSurvey == null) {
          Toast.fail('未找到该残疾人档案信息')
          return
        }
        vue.$set(vue, 'userRealName', userRealName) // 用户姓名
        disableSurvey = vue.surveyInfo.disableSurvey
        personInfo = vue.surveyInfo.personInfo
        if (vue.surveyInfo.historyData == null) {
          vue.surveyInfo.historyData = {}
        }
        historyData = vue.surveyInfo.historyData
        lowSecurity = vue.surveyInfo.lowSecurity
        dbc = vue.surveyInfo.disableSurvey.dbc
        lifeSubsidy = vue.surveyInfo.lifeSubsidy
        severeSubsidy = vue.surveyInfo.severeSubsidy
        dBarrierFree = vue.surveyInfo.barrierFree
        dHouseAssist = vue.surveyInfo.houseAssist
        dJob = vue.surveyInfo.job
        dJobHelp = vue.surveyInfo.jobHelp
        dSchool = vue.surveyInfo.school
        dShortHelp = vue.surveyInfo.shortHelp
        element = vue.element
        fillForm(vue) // 填充表单
        initLogic(vue)
        // 重新渲染组件
        vue.disableSurvey_survey_view = false
        vue.$nextTick(() => (vue.disableSurvey_survey_view = true))
      } else {
        Toast.fail(result.msg || '服务请求错误')
      }
    })
}

// 初始表单数据填充
function fillForm (vue) {
  let flag =
    personInfo == null || personInfo.id == null || !disableSurvey.modules
  /**
   * 残疾人情况
   */
  // 采集状态
  vue.$set(vue.formData.pstate, 'value', personInfo ? personInfo.pstate : '6')
  /**
   * 采集信息
   */
  // 采集方式
  vue.$set(
    vue.formData.dtype,
    'value',
    personInfo && personInfo.dtype ? personInfo.dtype : '1'
  )
  // 申报人
  vue.$set(
    vue.formData.declarant,
    'value',
    personInfo && personInfo.sbr ? personInfo.sbr : dbc.name
  )
  // 信息采集员
  let partner = ''
  let updateEmp = vue.userRealName
  if (personInfo && personInfo.updateEmp) {
    updateEmp = personInfo.updateEmp.replace(/[\s+,，]/g, ' ')
    if (updateEmp.indexOf(' ') > -1) {
      partner = updateEmp.substring(updateEmp.indexOf(' '))
      updateEmp = updateEmp.substring(0, updateEmp.indexOf(' '))
    }
  }
  vue.$set(vue.formData.collector, 'value', updateEmp)
  vue.$set(vue.formData.partner, 'value', partner ? partner : '')
  // 填表日期
  vue.$set(
    vue.formData.addTime,
    'value',
    dateUtil.dateFormat('yyyy-MM-dd hh:mm')
  )
  /**
   * 基本信息
   */
  let baseInfoFlag = flag || disableSurvey.modules.indexOf('BASE_INFO') < 0
  // 户口性质
  let householdTypeValue = personInfo && personInfo.r3 ? personInfo.r3 : ''
  householdTypeValue =
    householdTypeValue || (baseInfoFlag && historyData.r3 ? historyData.r3 : '')
  householdTypeValue =
    householdTypeValue ||
    (baseInfoFlag && JSON.stringify(historyData) == '{}' && dbc.householdType)
  if (householdTypeValue) {
    vue.$set(vue.formData.householdType, 'value', householdTypeValue)
  }
  // 婚姻状况
  let marriageValue = personInfo && personInfo.r4 ? personInfo.r4 : ''
  marriageValue =
    marriageValue || (baseInfoFlag && historyData.r4 ? historyData.r4 : '')
  marriageValue =
    marriageValue ||
    (baseInfoFlag &&
      JSON.stringify(historyData) == '{}' &&
      transMarriage(dbc.marriage))
  if (marriageValue) {
    vue.$set(vue.formData.marriage, 'value', marriageValue)
    vue.$set(
      vue.formData.marriage,
      'text',
      element.columns_marriage[marriageValue - 1].text
    )
  }
  function transMarriage (value) {
    switch (value) {
      case '10':
        return '1'
      case '20':
        return '2'
      case '40':
        return '3'
      case '30':
        return '4'
      default:
        return ''
    }
  }
  // 联系人姓名
  let contactNameValue = personInfo && personInfo.r5 ? personInfo.r5 : ''
  contactNameValue =
    contactNameValue || (baseInfoFlag && historyData.r5 ? historyData.r5 : '')
  contactNameValue =
    contactNameValue ||
    (baseInfoFlag && JSON.stringify(historyData) == '{}' && dbc.guardName
      ? dbc.guardName
      : '')
  if (contactNameValue) {
    vue.$set(vue.formData.contactName, 'value', contactNameValue)
  }
  // 固话
  let telephoneValue = personInfo && personInfo.r6_1 ? personInfo.r6_1 : ''
  telephoneValue =
    telephoneValue || (baseInfoFlag && historyData.r6_1 ? historyData.r6_1 : '')
  telephoneValue = telephoneValue || (baseInfoFlag && dbc.telephone)
  telephoneValue =
    telephoneValue ||
    (baseInfoFlag &&
    JSON.stringify(historyData) == '{}' &&
    dbc.mobilephone &&
    !regMobilephone.test(dbc.mobilephone)
      ? dbc.mobilephone
      : '')
  if (telephoneValue) {
    vue.$set(vue.formData.telephone, 'value', telephoneValue)
  }
  // 手机号
  let mobilephoneValue = personInfo && personInfo.r6_2 ? personInfo.r6_2 : ''
  mobilephoneValue =
    mobilephoneValue ||
    (baseInfoFlag && historyData.r6_2 ? historyData.r6_2 : '')
  mobilephoneValue =
    mobilephoneValue ||
    (baseInfoFlag &&
    JSON.stringify(historyData) == '{}' &&
    dbc.mobilephone &&
    regMobilephone.test(dbc.mobilephone)
      ? dbc.mobilephone
      : '')
  if (mobilephoneValue) {
    vue.$set(vue.formData.mobilephone, 'value', mobilephoneValue)
  }
  // 是否在养老院居住
  let nursingHouseValue = personInfo && personInfo.r7 ? personInfo.r7 : ''
  nursingHouseValue =
    nursingHouseValue || (baseInfoFlag && historyData.r7 ? historyData.r7 : '')
  if (nursingHouseValue) {
    vue.$set(vue.formData.nursingHouse, 'value', nursingHouseValue)
  }
  /**
   * 经济及住房
   */
  let economicFlag = flag || disableSurvey.modules.indexOf('ECONOMIC') < 0
  // 非农业 r8.家庭人均收入状况
  if (householdTypeValue == '2') {
    let nonfarmEconomyValue = personInfo && personInfo.r8 ? personInfo.r8 : ''
    if (
      !nonfarmEconomyValue &&
      economicFlag &&
      lowSecurity &&
      lowSecurity.salvationType
    ) {
      nonfarmEconomyValue = lowSecurity.salvationType
      if (lowSecurity.salvationType == '3') {
        nonfarmEconomyValue = '1'
      }
    }
    nonfarmEconomyValue =
      nonfarmEconomyValue ||
      (economicFlag && !lowSecurity && historyData.r8 ? historyData.r8 : '')
    if (nonfarmEconomyValue) {
      vue.$set(vue.formData.nonfarmEconomy, 'value', nonfarmEconomyValue)
      vue.$set(
        vue.formData.nonfarmEconomy,
        'text',
        element.columns_nonfarmEconomy[nonfarmEconomyValue - 1].text
      )
    }
    // 非农业 r9.家庭住房状况
    let nonfarmHousingValue = personInfo && personInfo.r9 ? personInfo.r9 : ''
    nonfarmHousingValue =
      nonfarmHousingValue ||
      (economicFlag && historyData.r9 && historyData.r9 != '4'
        ? historyData.r9
        : '')
    if (nonfarmHousingValue) {
      vue.$set(vue.formData.nonfarmHousing, 'value', nonfarmHousingValue)
      vue.$set(
        vue.formData.nonfarmHousing,
        'text',
        element.columns_nonfarmHousing[nonfarmHousingValue - 1].text
      )
    }
  }
  if (householdTypeValue == '1') {
    // 农业 r10.贫困与建档立卡状况
    let farmEconomyValue = personInfo && personInfo.r10 ? personInfo.r10 : ''
    farmEconomyValue =
      farmEconomyValue ||
      (economicFlag && lowSecurity && lowSecurity.salvationType ? '2' : '')
    farmEconomyValue =
      farmEconomyValue ||
      (economicFlag && !lowSecurity && historyData.r10 ? historyData.r10 : '')
    if (farmEconomyValue) {
      vue.$set(vue.formData.farmEconomy, 'value', farmEconomyValue)
      vue.$set(
        vue.formData.farmEconomy,
        'text',
        element.columns_farmEconomy[farmEconomyValue - 1].text
      )
    }
    // 农业 r11.家庭住房状况
    let farmHousingValue = personInfo && personInfo.r11 ? personInfo.r11 : ''
    farmHousingValue =
      farmHousingValue ||
      (economicFlag &&
      historyData.r11 &&
      historyData.r11 != '2' &&
      historyData.r11 != '3'
        ? historyData.r11
        : '')
    if (farmHousingValue) {
      vue.$set(vue.formData.farmHousing, 'value', farmHousingValue)
      vue.$set(
        vue.formData.farmHousing,
        'text',
        element.columns_farmHousing[farmHousingValue - 1].text
      )
    }
  }
  /**
   * 教育
   */
  let educationFlag = flag || disableSurvey.modules.indexOf('EDUCATON') < 0
  // r12.是否识字（15周岁及以上填报）
  if (dbc.age >= 15) {
    let literacyValue = personInfo && personInfo.r12 ? personInfo.r12 : ''
    literacyValue =
      literacyValue || (educationFlag && historyData.r12 ? historyData.r12 : '')
    if (literacyValue) {
      vue.$set(vue.formData.literacy, 'value', literacyValue)
    }
  }
  // r13.受教育程度
  let educationValue = personInfo && personInfo.r13 ? personInfo.r13 : ''
  educationValue =
    educationValue || (educationFlag && historyData.r13 ? historyData.r13 : '')
  if (educationValue) {
    vue.$set(vue.formData.education, 'value', educationValue)
    vue.$set(
      vue.formData.education,
      'text',
      element.columns_education[educationValue - 1].text
    )
  }
  // r14就读学校-普通/特殊
  let schoolValue = personInfo && personInfo.r14 ? personInfo.r14 : ''
  schoolValue =
    schoolValue || (educationFlag && historyData.r14 ? historyData.r14 : '')

  if (schoolValue && +schoolValue < 7) {
    vue.$set(vue.formData.generalSchool, 'value', schoolValue)
    vue.$set(
      vue.formData.generalSchool,
      'text',
      element.columns_generalSchool[+schoolValue].text
    )
  } else if (schoolValue && +schoolValue >= 7) {
    vue.$set(vue.formData.specialSchool, 'value', schoolValue)
    vue.$set(
      vue.formData.specialSchool,
      'text',
      element.columns_specialSchool[schoolValue - 6].text
    )
  }
  // r15未入学原因
  let notEnrolledReasonValue =
    personInfo && personInfo.r15 ? personInfo.r15 : ''
  notEnrolledReasonValue =
    notEnrolledReasonValue ||
    (educationFlag && historyData.r15 ? historyData.r15 : '')
  if (notEnrolledReasonValue) {
    vue.$set(vue.formData.notEnrolledReason, 'value', notEnrolledReasonValue)
    vue.$set(
      vue.formData.notEnrolledReason,
      'text',
      element.columns_notEnrolledReason[notEnrolledReasonValue - 1].text
    )
  }
  /**
   * 就业扶贫16-59周岁填报
   */
  if (dbc.age >= 16 && dbc.age <= 59) {
    let jobFlag = flag || disableSurvey.modules.indexOf('JOB') < 0
    // r16.是否就业
    let employValue = personInfo && personInfo.r16 ? personInfo.r16 : ''
    employValue = employValue || (jobFlag && dJob ? '1' : '')
    employValue =
      employValue || (jobFlag && historyData.r16 ? historyData.r16 : '')
    if (employValue) {
      vue.$set(vue.formData.employ, 'value', employValue)
    }
    // r17.残疾人就业形式
    let employTypeValue = personInfo && personInfo.r17 ? personInfo.r17 : ''
    employTypeValue =
      employTypeValue || (jobFlag && dJob && dJob.type != '0' ? dJob.type : '')
    employTypeValue =
      employTypeValue || (jobFlag && historyData.r17 ? historyData.r17 : '')

    if (employTypeValue) {
      vue.$set(vue.formData.employType, 'value', employTypeValue)
      vue.$set(
        vue.formData.employType,
        'text',
        element.columns_employType[employTypeValue - 1].text
      )
    }
    // r18.未就业生活来源
    let unemployedIncomeValue =
      personInfo && personInfo.r18 ? personInfo.r18 : ''
    unemployedIncomeValue =
      unemployedIncomeValue ||
      (jobFlag && historyData.r18 ? historyData.r18 : '')
    if (unemployedIncomeValue) {
      vue.$set(vue.formData.unemployedIncome, 'value', unemployedIncomeValue)
      vue.$set(
        vue.formData.unemployedIncome,
        'text',
        element.columns_unemployedIncome[unemployedIncomeValue - 1].text
      )
    }
    // r19.未就业原因
    let unemployedReasonValue =
      personInfo && personInfo.r19 ? personInfo.r19 : ''
    unemployedReasonValue =
      unemployedReasonValue ||
      (jobFlag && historyData.r19 ? historyData.r19 : '')
    if (unemployedReasonValue) {
      vue.$set(vue.formData.unemployedReason, 'value', unemployedReasonValue)
      vue.$set(
        vue.formData.unemployedReason,
        'text',
        element.columns_unemployedReason[unemployedReasonValue - 1].text
      )
    }
    // r20.就业扶贫帮扶
    let employAssistValue = personInfo && personInfo.r20 ? personInfo.r20 : ''
    employAssistValue =
      employAssistValue || (jobFlag && historyData.r21 ? historyData.r21 : '')
    if (employAssistValue) {
      vue.formData.employAssist = employAssistValue.split(',')
    }
    if (jobFlag && dJobHelp) {
      let index = vue.formData.employAssist.indexOf(dJobHelp.type)
      if (index < 0) {
        vue.formData.employAssist.push(dJobHelp.type)
      }
    }
    if (vue.formData.employAssist.length > 1) {
      let index6 = vue.formData.employAssist.indexOf('6')
      if (index6 > -1) {
        deleteArrItems(vue, vue.formData.employAssist, '6')
      }
    }

    // r21.就业扶贫需求
    let employAssistNeedValue =
      personInfo && personInfo.r21 ? personInfo.r21 : ''
    if (employAssistNeedValue) {
      vue.formData.employAssistNeed = employAssistNeedValue.split(',')
    }
  }
  /**
   * 社会保障
   */
  let socialSecurityFlag =
    flag || disableSurvey.modules.indexOf('SOCIAL_SECURITY') < 0
  // r22.是否参加职工社会保险
  let socialInsuranceValue = personInfo && personInfo.r22 ? personInfo.r22 : ''
  socialInsuranceValue =
    socialInsuranceValue ||
    (socialSecurityFlag && historyData.r22 ? historyData.r22 : '')
  if (socialInsuranceValue) {
    vue.formData.socialInsurance = socialInsuranceValue.split(',')
  }
  // r23.是否参加城乡居民养老保险
  let endowmentInsuranceValue =
    personInfo && personInfo.r23 ? personInfo.r23 : ''
  endowmentInsuranceValue =
    endowmentInsuranceValue ||
    (socialSecurityFlag && historyData.r23 ? historyData.r23 : '')
  if (endowmentInsuranceValue) {
    vue.$set(vue.formData.endowmentInsurance, 'value', endowmentInsuranceValue)
  }
  // r24.是否享受居民养老保险补贴
  let endowmentSubsidyValue = personInfo && personInfo.r24 ? personInfo.r24 : ''
  endowmentSubsidyValue =
    endowmentSubsidyValue ||
    (socialSecurityFlag && historyData.r24 ? historyData.r24 : '')
  if (endowmentSubsidyValue) {
    vue.$set(vue.formData.endowmentSubsidy, 'value', endowmentSubsidyValue)
  }
  // r25.是否享受医疗保险
  let medicalInsuranceValue = personInfo && personInfo.r25 ? personInfo.r25 : ''
  medicalInsuranceValue =
    medicalInsuranceValue ||
    (socialSecurityFlag && historyData.r25 ? historyData.r25 : '')
  if (medicalInsuranceValue) {
    vue.$set(vue.formData.medicalInsurance, 'value', medicalInsuranceValue)
  }
  // r26.是否享受医疗保险补贴
  let medicalSubsidyValue = personInfo && personInfo.r26 ? personInfo.r26 : ''
  medicalSubsidyValue =
    medicalSubsidyValue ||
    (socialSecurityFlag && historyData.r26 ? historyData.r26 : '')
  if (medicalSubsidyValue) {
    vue.$set(vue.formData.medicalSubsidy, 'value', medicalSubsidyValue)
  }
  // r27.社会救助
  let socialAssistValue = personInfo && personInfo.r27 ? personInfo.r27 : ''
  socialAssistValue =
    socialAssistValue ||
    (socialSecurityFlag && historyData.r27 ? historyData.r27 : '')
  let socialAssistArr = socialAssistValue ? socialAssistValue.split(',') : []
  if (socialSecurityFlag && lowSecurity && lowSecurity.salvationType) {
    if (lowSecurity.salvationType == '1' && socialAssistArr.indexOf('1') < 0) {
      socialAssistArr.push('1')
      let index1 = socialAssistArr.indexOf('2')
      if (index1 > -1) {
        socialAssistArr.splice(index1, 1)
      }
    } else if (
      lowSecurity.salvationType == '3' &&
      socialAssistArr.indexOf('2') < 0
    ) {
      socialAssistArr.push('2')
      let index2 = socialAssistArr.indexOf('1')
      if (index2 > -1) {
        socialAssistArr.splice(index2, 1)
      }
    }
  }
  if (socialSecurityFlag && dHouseAssist) {
    let index5 = socialAssistArr.indexOf('5')
    if (index5 < 0) {
      socialAssistArr.push('5')
    }
  }
  if (socialSecurityFlag && dShortHelp) {
    let index4 = socialAssistArr.indexOf('4')
    if (index4 < 0) {
      socialAssistArr.push('4')
    }
  }
  if (socialAssistArr.length > 1) {
    let index3 = socialAssistArr.indexOf('6')
    if (index3 > -1) {
      socialAssistArr.splice(index3, 1)
    }
  }
  vue.formData.socialAssist = socialAssistArr.sort()
  if (socialSecurityFlag && !lowSecurity) {
    deleteArrItems(vue, vue.formData.socialAssist, '1')
  }
  if (socialSecurityFlag && !dHouseAssist) {
    deleteArrItems(vue, vue.formData.socialAssist, '5')
  }

  // r28.社会福利补贴
  let socialWelfareValue = personInfo && personInfo.r28 ? personInfo.r28 : ''
  socialWelfareValue =
    socialWelfareValue ||
    (socialSecurityFlag && historyData.r28 ? historyData.r28 : '')
  let socialWelfareArr = socialWelfareValue ? socialWelfareValue.split(',') : []
  if (socialSecurityFlag && lifeSubsidy && socialWelfareArr.indexOf('1') < 0) {
    socialWelfareArr.push('1')
  }
  if (
    socialSecurityFlag &&
    severeSubsidy &&
    socialWelfareArr.indexOf('2') < 0
  ) {
    socialWelfareArr.push('2')
  }
  if (socialWelfareArr.length > 1) {
    let index = socialWelfareArr.indexOf('4')
    if (index > -1) {
      socialWelfareArr.splice(index, 1)
    }
  }
  vue.formData.socialWelfare = socialWelfareArr.sort()
  //  r29.是否享受托养服务
  if (dbc.age >= 16 && dbc.age <= 59) {
    let fosterValue = personInfo && personInfo.r29 ? personInfo.r29 : ''
    fosterValue =
      fosterValue ||
      (socialSecurityFlag && historyData.r30 && historyData.r30 != '4'
        ? '1'
        : historyData.r30 == '4'
        ? '2'
        : '')
    if (fosterValue) {
      vue.$set(vue.formData.foster, 'value', fosterValue)
    }
    // r30.托养服务需求
    let fosterNeedValue = personInfo && personInfo.r30 ? personInfo.r30 : ''
    if (fosterNeedValue) {
      vue.$set(vue.formData.fosterNeed, 'value', fosterNeedValue)
      vue.$set(
        vue.formData.fosterNeed,
        'text',
        element.columns_fosterNeed[fosterNeedValue - 1].text
      )
    }
  }
  /**
   * 基本医疗与康复
   */
  let medicalFlag = flag || disableSurvey.modules.indexOf('MEDICAL') < 0
  // r31.家庭医生服务协议
  let familyDoctorValue = personInfo && personInfo.r31 ? personInfo.r31 : ''
  familyDoctorValue =
    familyDoctorValue || (medicalFlag && historyData.r31 ? historyData.r31 : '')
  if (familyDoctorValue) {
    vue.$set(vue.formData.familyDoctor, 'value', familyDoctorValue)
  }
  // r32.过去两周是否患有疾病
  let sickValue = personInfo && personInfo.r32 ? personInfo.r32 : ''
  if (sickValue) {
    vue.$set(vue.formData.sick, 'value', sickValue)
  }
  // r33.过去两周是否已就诊或治疗
  let sickCureValue = personInfo && personInfo.r33 ? personInfo.r33 : ''
  if (sickCureValue) {
    vue.$set(vue.formData.sickCure, 'value', sickCureValue)
  }
  // r34.未就诊或治疗原因
  let notCureReasonValue = personInfo && personInfo.r34 ? personInfo.r34 : ''
  if (notCureReasonValue) {
    vue.formData.notCureReason = notCureReasonValue.split(',')
  }
  // r35.康复服务
  let rehabilitationValue = personInfo && personInfo.r35 ? personInfo.r35 : ''
  rehabilitationValue =
    rehabilitationValue ||
    (medicalFlag && historyData.r37 ? historyData.r37 : '')
  if (rehabilitationValue) {
    vue.formData.rehabilitation = rehabilitationValue.split(',')
  }
  // 业务支撑
  if (medicalFlag && vue.surveyInfo.medicineSubsidy != null) {
    if (vue.formData.rehabilitation.indexOf('2') < 0) {
      vue.formData.rehabilitation.push('2')
      deleteArrItems(vue, vue.formData.rehabilitation, '6')
    }
  }
  // r36.未得到康复服务原因
  let noRehabilitationReasonValue =
    personInfo && personInfo.r36 ? personInfo.r36 : ''
  if (noRehabilitationReasonValue) {
    vue.formData.noRehabilitationReason = noRehabilitationReasonValue.split(',')
  }
  // r37.康复服务需求
  let rehabilitationNeedValue =
    personInfo && personInfo.r37 ? personInfo.r37 : ''
  if (rehabilitationNeedValue) {
    vue.formData.rehabilitationNeed = rehabilitationNeedValue.split(',')
  }
  /**
   * 无障碍
   */
  let barrierFreeFlag =
    flag || disableSurvey.modules.indexOf('BARRIER_FREE') < 0
  // r38.无障碍改造
  let barrierFreeValue = personInfo && personInfo.r38 ? personInfo.r38 : ''
  barrierFreeValue =
    barrierFreeValue || (barrierFreeFlag && dBarrierFree != null ? '1' : '')
  barrierFreeValue =
    barrierFreeValue ||
    (barrierFreeFlag && historyData.r38 == '1' ? historyData.r38 : '')
  barrierFreeValue =
    barrierFreeValue ||
    (barrierFreeFlag && historyData.r39 && historyData.r39 != '9' ? '1' : '')
  if (barrierFreeValue) {
    vue.$set(vue.formData.barrierFree, 'value', barrierFreeValue)
  }
  // r39.无障碍改造需求
  let barrierFreeNeedValue = personInfo && personInfo.r39 ? personInfo.r39 : ''
  if (barrierFreeNeedValue) {
    vue.formData.barrierFreeNeed = barrierFreeNeedValue.split(',')
  }

  /**
   * 文化体育
   */
  let sportsFlag = flag || disableSurvey.modules.indexOf('SPORTS') < 0
  // r40.是否经常参加文化体育活动
  let activityValue = personInfo && personInfo.r40 ? personInfo.r40 : ''
  activityValue =
    activityValue || (sportsFlag && historyData.r40 ? historyData.r40 : '')
  if (activityValue) {
    vue.$set(vue.formData.activity, 'value', activityValue)
  }
  // r41.不能经常参加文化体育活动原因
  let inactivityReasonValue = personInfo && personInfo.r41 ? personInfo.r41 : ''
  inactivityReasonValue =
    inactivityReasonValue ||
    (sportsFlag && historyData.r41 ? historyData.r41 : '')
  if (inactivityReasonValue) {
    vue.formData.inactivityReason = inactivityReasonValue.split(',')
  }
  /**
   * 补充问题
   */
  let suppleInfoFlag = flag || disableSurvey.modules.indexOf('SUPPLE_INFO') < 0
  let hostNameValue = personInfo && personInfo.hzxm ? personInfo.hzxm : ''
  hostNameValue =
    hostNameValue ||
    (suppleInfoFlag && historyData.hzxm ? historyData.hzxm : '')
  if (hostNameValue) {
    vue.$set(vue.formData.hostName, 'value', hostNameValue)
    if (hostNameValue == '集体户口') {
      vue.$set(vue.formData.collectiveHousehold, 'value', '1')
    } else {
      vue.$set(vue.formData.collectiveHousehold, 'value', '2')
    }
  } else {
    vue.$set(vue.formData.collectiveHousehold, 'value', '2')
  }
  let hostIdentityCardValue =
    personInfo && personInfo.hzsfzh ? personInfo.hzsfzh : ''
  hostIdentityCardValue =
    hostIdentityCardValue ||
    (suppleInfoFlag && historyData.hzsfzh ? historyData.hzsfzh : '')
  if (!hostNameValue || hostNameValue != '集体户口') {
    vue.$set(vue.formData.hostIdentityCard, 'value', hostIdentityCardValue)
  }
  // 根据不同地区修改提示语
  if (/^3301.*/.test(dbc.areaCode)) {
    // 杭州市
    let message = formElement.element.tips.socialAssist_eco.message
    vue.$set(
      vue.element.tips.socialAssist_eco,
      'message',
      (message += '；注：残保应选择经济状况为其他，并勾选最低生活保障！')
    )
  }
  /**
   * 图片
   */
  _http
    .post(
      '/disableSurvey/getImg/' + dbc.identityCard,
      {},
      {
        'Content-Type': 'application/x-www-form-urlencoded'
      }
    )
    .then(result => {
      if (result && result.code == 200) {
        if (result.data.base64) {
          vue.formData.fileList.push({ content: result.data.base64 })
        }
      }
    })
}

// 逻辑初始化
function initLogic (vue) {
  // 残疾人情况
  initDisableState(vue)
  // r4.婚姻状况
  initMarriage(vue)
  // r5.联系人姓名
  initContactName(vue)
  // 相关栏目初始化
  if (isLiveNursing(vue)) {
    disNonNursing(vue)
  }
  if (!isLiveNursing(vue)) {
    initEconomic(vue)
  }
  // r12.是否识字
  initLiteracy(vue)
  // r13.受教育程度
  initEducation(vue)
  // r14.就读学校
  initSchool(vue)
  // r15.未入学原因
  initNotEnrolledReason(vue)
  // 判断是否可以填写就业栏目
  if (!isEnableJob(vue)) {
    disJob(vue)
  } else {
    initJob(vue)
  }
  initSocialSecurity(vue) // 社会保障模块
  // r33.过去两周是否已就诊或治疗
  initSickCure(vue)
  // r34.未就诊或治疗原因
  initNotCureReason(vue)
  // r35.康复服务
  initRehabilitation(vue)
  // r36.未得到康复服务的原因
  initNoRehabilitationReason(vue)
  // r37.康复服务需求
  initRehabilitationNeed(vue)
  if (!isLiveNursing(vue)) {
    // r38.无障碍改造需求
    initBarrierFreeNeed(vue)
  }
  if (isEnableSports(vue)) {
    // r40.不经常参加文化体育活动的原因
    initInactivityReason(vue)
  } else {
    disSports(vue)
  }
  // 户主和户主身份证号
  if (!isLiveNursing(vue)) {
    initHouseholder(vue)
  }
}
// 初始化逻辑：残疾人情况
function initDisableState (vue) {
  let pstate = vue.formData.pstate
  if (pstate && pstate.value != '6') {
    disPstate(vue)
  }
}
// r4.婚姻状况(20周岁及以上填报)
function initMarriage (vue) {
  let lastMarriageValue = historyData.r4
  if (lastMarriageValue && parseInt(lastMarriageValue) > 1) {
    setDisabled(vue, vue.element.columns_marriage[0])
    if (vue.formData.marriage.value == '1') {
      resetFormData(vue, [vue.formData.marriage])
    }
  }
  if (dbc.age < 20) {
    setDisabled(vue, vue.element.modulesValid.marriage)
    resetFormData(vue, [vue.formData.marriage])
  }
}
// r5.初始化逻辑：联系人姓名
function initContactName (vue) {
  let flag =
    (dbc.kindstr &&
      (dbc.kindstr.indexOf('5') > -1 || dbc.kindstr.indexOf('6') > -1)) ||
    dbc.age < 18
  if (!flag) {
    resetFormData(vue, [vue.formData.contactName])
    setDisabled(vue, vue.element.modulesValid.contactName)
  }
}

// 初始化经济与住房模块
function initEconomic (vue) {
  initNonFarmEconomy(vue) // 非农业家庭人均收入状况
  initNonFarmHousing(vue) // 非农业家庭住房状况
  initFarmEconomy(vue) // 农业贫困与建档立卡状况
  initFarmHousing(vue) // 农业家庭住房状况
}

/**
 * r8.初始化逻辑：非农业家庭人均收入状况
 * 1.若户口性质为农业，禁止填写
 */
function initNonFarmEconomy (vue) {
  let householdTypeValue = vue.formData.householdType.value
  if (householdTypeValue == '1') {
    setDisabled(vue, vue.element.modulesValid.nonfarm)
    resetFormData(vue, [vue.formData.nonfarmEconomy])
  } else {
    setDisabled(vue, vue.element.modulesValid.nonfarm, false)
  }
}
/**
 * r9.初始化逻辑：非农业家庭住房状况
 * 1.若户口性质为农业，禁止填写
 */
function initNonFarmHousing (vue) {
  let householdTypeValue = vue.formData.householdType.value
  if (householdTypeValue == '1') {
    setDisabled(vue, vue.element.modulesValid.nonfarm)
    resetFormData(vue, [vue.formData.nonfarmHousing])
  } else {
    setDisabled(vue, vue.element.modulesValid.nonfarm, false)
  }
}
/**
 * r10.初始化逻辑：农业贫困与建档立卡状况
 * 1.若户口性质为非农业，禁止填写
 */
function initFarmEconomy (vue) {
  let householdTypeValue = vue.formData.householdType.value
  if (householdTypeValue == '2') {
    setDisabled(vue, vue.element.modulesValid.farm)
    resetFormData(vue, [vue.formData.farmEconomy])
  } else {
    setDisabled(vue, vue.element.modulesValid.farm, false)
  }
}
/**
 * r11.初始化逻辑：农业家庭住房状况
 * 1.若户口性质为非农业，禁止填写
 */
function initFarmHousing (vue) {
  let householdTypeValue = vue.formData.householdType.value
  if (householdTypeValue == '2') {
    setDisabled(vue, vue.element.modulesValid.farm)
    resetFormData(vue, [vue.formData.farmHousing])
  } else {
    setDisabled(vue, vue.element.modulesValid.farm, false)
  }
}

/**
 * r12.初始化逻辑：是否识字
 * 1.年龄小于15岁，禁止填写
 * 2.上年度识字，今年必须是识字
 */
function initLiteracy (vue) {
  if (dbc.age < 15) {
    setDisabled(vue, vue.element.modulesValid.literacy)
    resetFormData(vue, [vue.formData.literacy])
  } else {
    let lastLiteracyValue = historyData.r12
    if (lastLiteracyValue == '1') {
      vue.$set(vue.formData.literacy, 'value', '1')
      setDisabled(vue, vue.element.modulesValid.literacy_2)
    } else {
      setDisabled(vue, vue.element.modulesValid.literacy_2, false)
    }
  }
}
/**
 * r13.初始化逻辑：受教育程度
 * 1.若年龄小于15岁，禁止填写
 * 2.若r12勾选不识字，则受教育程度最多只能勾选到高中
 * 3.今年填报的受教育程度不得低于去年
 */
function initEducation (vue) {
  if (dbc.age < 15) {
    setDisabled(vue, vue.element.modulesValid.educationLevel)
    resetFormData(vue, [vue.formData.education])
  }
  {
    let literacyValue = vue.formData.literacy.value
    if (literacyValue == '2') {
      disNonLiteracy_education(vue)
    } else {
      setDisabled(vue, element.columns_education, false)
    }
    let lastV = historyData.r13
    let v = vue.formData.education
    if (lastV) {
      setDisabled(vue, vue.element.columns_education.slice(0, lastV - 1))
      if (v && parseInt(v) < parseInt(lastV)) {
        resetFormData(vue, [vue.formData.education])
      }
    }
  }
}
/**
 * r14.初始化逻辑：就读学校
 * 1.若r12勾选不识字，则就读学校最多只能勾选到高中
 * 2.若r13受教育程度有值，则就读学校要和受教育程度对应，若从未上过学，就读学校禁止填写
 * 3.若年龄大于等于60岁，就读学校禁止填写
 * 4.若年龄大于等于35周岁，且就读学校有值，给予提示：年龄≥35岁，确定在上学？
 */
function initSchool (vue) {
  let literacyValue = vue.formData.literacy.value
  if (literacyValue == '2') {
    disNonLiteracy_school(vue)
  } else {
    setDisabled(vue, element.columns_generalSchool, false)
    setDisabled(vue, element.columns_specialSchool, false)
  }
  let educationValue = vue.formData.education.value
  if (educationValue == '1' || dbc.age >= 60) {
    disSchool(vue)
  } else {
    setDisabled(vue, vue.element.modulesValid.school, false)
    if (educationValue) {
      let generalValue = vue.formData.generalSchool.value
      let specialValue = vue.formData.specialSchool.value
      let v = generalValue || (specialValue ? specialValue - 6 : null)
      let ev = +educationValue > 6 ? educationValue - 1 : +educationValue
      if (ev != v) {
        resetFormData(vue, [
          vue.formData.generalSchool,
          vue.formData.specialSchool
        ])
      }
      setDisabled(vue, vue.element.columns_generalSchool.slice(ev + 1))
      setDisabled(vue, vue.element.columns_generalSchool.slice(1, ev))
      setDisabled(vue, vue.element.columns_specialSchool.slice(ev + 1))
      setDisabled(vue, vue.element.columns_specialSchool.slice(1, ev))
    }
  }
  if (dbc.age >= 35 && dbc.age < 60) {
    let generalValue = vue.formData.generalSchool.value
    let specialValue = vue.formData.specialSchool.value
    if (generalValue || specialValue) {
      setDisabled(vue, vue.element.tips.school, false)
    } else {
      setDisabled(vue, vue.element.tips.school)
    }
  }
}
/**
 * r15.初始化逻辑：未入学原因
 * 1.若年龄不在6-14周岁，则禁止填写
 * 2.若已入学，禁止填写
 */
function initNotEnrolledReason (vue) {
  let bool =
    dbc.age >= 6 &&
    dbc.age <= 14 &&
    !vue.formData.generalSchool.value &&
    !vue.formData.specialSchool.value
  if (!bool) {
    setDisabled(vue, vue.element.modulesValid.notEnrolledReason)
    resetFormData(vue, [vue.formData.notEnrolledReason])
  } else {
    setDisabled(vue, vue.element.modulesValid.notEnrolledReason, false)
  }
}
function initJob (vue) {
  initEmploy(vue) // 是否就业
  initEmployType(vue) // 就业形式
  initUnemployedIncome(vue) // 未就业生活来源
  initUnemployedReason(vue) // 未就业主要原因
  initEmployAssist(vue) // 就业帮扶
  initEmployAssistNeed(vue) // 就业帮扶需求
}
/**
 * r16.初始化逻辑：是否就业
 * 1.若正在上学，则就业选择否，禁用就业第一项是
 */
function initEmploy (vue) {
  let generalValue = vue.formData.generalSchool.value
  let specialValue = vue.formData.specialSchool.value
  if (generalValue || specialValue) {
    vue.$set(vue.formData.employ, 'value', '2')
    setDisabled(vue, vue.element.modulesValid.employ_1)
  } else {
    setDisabled(vue, vue.element.modulesValid.employ_1, false)
  }
}
/**
 * r17.初始化逻辑：就业形式
 * 1.若就业选择是，则启用，否则禁用
 */
function initEmployType (vue) {
  let employValue = vue.formData.employ.value
  if (!(employValue == '1')) {
    setDisabled(vue, vue.element.modulesValid.employType)
    resetFormData(vue, [vue.formData.employType])
  } else {
    setDisabled(vue, vue.element.modulesValid.employType, false)
  }
}
/**
 * r18.初始化逻辑：未就业生活来源
 * 1.若就业选择否，则启用，否则禁用
 * 2.若选择1.退休金且年龄小于等于45周岁，提示此人未到退休年龄
 */
function initUnemployedIncome (vue) {
  let employValue = vue.formData.employ.value
  if (!(employValue == '2')) {
    setDisabled(vue, vue.element.modulesValid.unemployedIncome)
    resetFormData(vue, [vue.formData.unemployedIncome])
  } else {
    setDisabled(vue, vue.element.modulesValid.unemployedIncome, false)
    let v = vue.formData.unemployedIncome.value
    if (v == '1' && dbc.age <= 45) {
      setDisabled(vue, vue.element.tips.unemployedIncome, false)
    } else {
      setDisabled(vue, vue.element.tips.unemployedIncome)
    }
  }
}
/**
 * r19.初始化逻辑：未就业主要原因
 * 1.若就业选择否，则启用，否则禁用
 * 2.若就业选择否，且上学，则选择1.在校学习，其他禁用。反过来，在校学习禁用，其他启用
 * 3.若选择2.退休且年龄小于等于45周岁，提示此人未到退休年龄
 */
function initUnemployedReason (vue) {
  let employValue = vue.formData.employ.value
  if (!(employValue == '2')) {
    setDisabled(vue, vue.element.modulesValid.unemployedReason)
    resetFormData(vue, [vue.formData.unemployedReason])
  } else {
    setDisabled(vue, vue.element.modulesValid.unemployedReason, false)
    let schoolValue =
      vue.formData.generalSchool.value || vue.formData.specialSchool.value
    if (schoolValue) {
      setDisabled(vue, vue.element.columns_unemployedReason[0], false)
      setDisabled(vue, vue.element.columns_unemployedReason.slice(1))
      vue.$set(vue.formData.unemployedReason, 'value', '1')
      vue.$set(
        vue.formData.unemployedReason,
        'text',
        vue.element.columns_unemployedReason[0].text
      )
    } else {
      setDisabled(vue, vue.element.columns_unemployedReason[0])
      setDisabled(vue, vue.element.columns_unemployedReason.slice(1), false)
      if (vue.formData.unemployedReason.value == '1') {
        resetFormData(vue, [vue.formData.unemployedReason])
      }
    }
    let v = vue.formData.unemployedReason.value
    if (v == '2' && dbc.age <= 45) {
      setDisabled(vue, vue.element.tips.unemployedReason, false)
    } else {
      setDisabled(vue, vue.element.tips.unemployedReason)
    }
  }
}
/**
 * r20.初始化逻辑：就业帮扶
 * 1.若未就业原因值为1.在校学习，2.退休，3.无就业意愿，5.丧失劳动能力，则禁填
 */
function initEmployAssist (vue) {
  let unemployedReasonValue = vue.formData.unemployedReason.value
  if (
    unemployedReasonValue == '1' ||
    unemployedReasonValue == '2' ||
    unemployedReasonValue == '3' ||
    unemployedReasonValue == '5'
  ) {
    disEmployAssist(vue)
  } else {
    setDisabled(vue, vue.element.modulesValid.employAssist, false)
  }
}
/**
 * r21.初始化逻辑：就业帮扶需求
 * 1.若未就业原因值为1.在校学习，2.退休，3.无就业意愿，5.丧失劳动能力，则禁填
 */
function initEmployAssistNeed (vue) {
  let unemployedReasonValue = vue.formData.unemployedReason.value
  if (
    unemployedReasonValue == '1' ||
    unemployedReasonValue == '2' ||
    unemployedReasonValue == '3' ||
    unemployedReasonValue == '5'
  ) {
    disEmployAssistNeed(vue)
  } else {
    setDisabled(vue, vue.element.modulesValid.employAssistNeed, false)
  }
}
/**
 * 初始化社会保障模块选项
 */
function initSocialSecurity (vue) {
  initSocialInsurance(vue) // 社会职工保险
  initEndowmentInsurance(vue) // 居民养老保险
  initEndowmentSubsidy(vue) // 居民养老补贴
  initMedicalInsurance(vue) // 居民医疗保险
  initMedicalSubsidy(vue) // 居民医疗补贴
  initSocialAssist(vue) // 社会救助
  initSocialWelfare(vue) // 社会福利补贴
  initFoster(vue) // 托养
  initFosterNeed(vue) // 托养服务需求
}
/**
 * r22.初始化逻辑：社会职工保险
 * 1.16周岁及以上填报
 * 2.若未就业原因为1.在校学习，禁填
 * 3.若就业形式为1.按比例就业或2.集中就业，若未勾选职工保险，提示：勾选了按比例就业/集中就业，原则上有职工保险
 * 4.若在校读书且勾选了职工养老保险且就业模块禁填，提示：此人正在上学，原则上无养老保险
 */
function initSocialInsurance (vue) {
  if (dbc.age < 16 || vue.formData.unemployedReason.value == '1') {
    setDisabled(vue, vue.element.modulesValid.socialInsurance)
    resetFormData(vue, [vue.formData.socialInsurance])
  } else {
    setDisabled(vue, vue.element.modulesValid.socialInsurance, false)
    let v = vue.formData.socialInsurance
    let employTypeValue = vue.formData.employType.value
    let schoolValue =
      vue.formData.generalSchool.value || vue.formData.specialSchool.value
    if (
      (employTypeValue == '1' || employTypeValue == '2') &&
      v &&
      v.indexOf('4') > -1
    ) {
      setDisabled(vue, vue.element.tips.socialInsurance_1, false)
    } else {
      setDisabled(vue, vue.element.tips.socialInsurance_1)
    }
    if (!isEnableJob(vue) && schoolValue && v && v.indexOf('1') > -1) {
      setDisabled(vue, vue.element.tips.socialInsurance_2, false)
    } else {
      setDisabled(vue, vue.element.tips.socialInsurance_2)
    }
  }
}
/**
 * r23.初始化逻辑：居民养老保险
 * 1.16周岁及以上填报
 * 2.若未就业原因为1.在校学习，禁填
 * 3.若职工保险勾选了职工养老保险，则居民养老保险第一项禁用
 * 4.若在校读书且居民养老保险为是且就业模块禁填，提示：此人正在上学，原则上无养老保险
 */
function initEndowmentInsurance (vue) {
  if (dbc.age < 16 || vue.formData.unemployedReason.value == '1') {
    setDisabled(vue, vue.element.modulesValid.endowmentInsurance)
    resetFormData(vue, [vue.formData.endowmentInsurance])
  } else {
    setDisabled(vue, vue.element.modulesValid.endowmentInsurance, false)
    let socialInsuranceValue = vue.formData.socialInsurance
    if (socialInsuranceValue && socialInsuranceValue.indexOf('1') > -1) {
      vue.$set(vue.formData.endowmentInsurance, 'value', '2')
      setDisabled(vue, vue.element.modulesValid.endowmentInsurance_1)
    } else {
      setDisabled(vue, vue.element.modulesValid.endowmentInsurance_1, false)
      let v = vue.formData.endowmentInsurance.value
      let schoolValue =
        vue.formData.generalSchool.value || vue.formData.specialSchool.value
      if (v == '1' && schoolValue && !isEnableJob(vue)) {
        setDisabled(vue, vue.element.tips.endowmentInsurance, false)
      } else {
        setDisabled(vue, vue.element.tips.endowmentInsurance)
      }
    }
  }
}
/**
 * r24.初始化逻辑：居民养老保险补贴
 * 1.16-59周岁之外，禁填
 * 2.若居民养老保险为否，禁填
 * 3.若未就业原因为1.在校学习 禁填
 */
function initEndowmentSubsidy (vue) {
  let endowmentInsuranceValue = vue.formData.endowmentInsurance.value
  let flag = dbc.age < 16 || dbc.age > 59
  flag =
    flag ||
    endowmentInsuranceValue == '2' ||
    vue.formData.unemployedReason.value == '1'
  if (flag) {
    setDisabled(vue, vue.element.modulesValid.endowmentSubsidy)
    resetFormData(vue, [vue.formData.endowmentSubsidy])
  } else {
    setDisabled(vue, vue.element.modulesValid.endowmentSubsidy, false)
  }
}
/**
 * r25.初始化逻辑：居民医疗保险
 * 1.若职工医疗保险勾选，则居民医疗保险第一项禁用
 */
function initMedicalInsurance (vue) {
  let socialInsuranceValue = vue.formData.socialInsurance
  if (socialInsuranceValue && socialInsuranceValue.indexOf('2') > -1) {
    vue.$set(vue.formData.medicalInsurance, 'value', '2')
    setDisabled(vue, vue.element.modulesValid.medicalInsurance_1)
  } else {
    setDisabled(vue, vue.element.modulesValid.medicalInsurance_1, false)
  }
}
/**
 * r26.初始化逻辑：居民医疗保险补贴
 * 1.若居民医疗保险为否，禁填
 */
function initMedicalSubsidy (vue) {
  let medicalInsuranceValue = vue.formData.medicalInsurance.value
  if (medicalInsuranceValue == '2') {
    setDisabled(vue, vue.element.modulesValid.medicalSubsidy)
    resetFormData(vue, [vue.formData.medicalSubsidy])
  } else {
    setDisabled(vue, vue.element.modulesValid.medicalSubsidy, false)
  }
}
/**
 * r27.初始化逻辑：社会救助
 * 1.若居民医疗缴费为是，则选中医疗救助
 * 2.若默认选中低保，则取消选中特困人员供养
 * 3.若经济状况为勾选了其他，且勾选了1.低保或2.特困供养，进行提示：经济状况勾选了其他！
 * 4.若户口性质为非农业，禁用第5项危房救助
 * 5.若勾选5.危房救助政策，且家庭住房状况不是状况良好，提示：勾选了住房状况为,确定享受住房政策？
 */
function initSocialAssist (vue) {
  let medicalSubsidyValue = vue.formData.medicalSubsidy.value
  if (medicalSubsidyValue == '1') {
    // 选中医疗救助，并设为只读，且禁用第6项无
    if (vue.formData.socialAssist.indexOf('3') < 0) {
      vue.formData.socialAssist.push('3')
    }
    vue.$set(vue.element.columns_socialAssist[2], 'readonly', true)
    setDisabled(vue, vue.element.columns_socialAssist[5])
    deleteArrItems(vue, vue.formData.socialAssist, '6')
  } else {
    vue.$set(vue.element.columns_socialAssist[2], 'readonly', false)
    setDisabled(vue, vue.element.columns_socialAssist[5], false)
  }
  let v = vue.formData.socialAssist
  if (v.indexOf('1') > -1 && v.indexOf('2') > -1) {
    deleteArrItems(vue, vue.formData.socialAssist, '2')
  }
  let economicValue =
    vue.formData.nonfarmEconomy.value || vue.formData.farmEconomy.value
  if (economicValue == '3' && (v.indexOf('1') > -1 || v.indexOf('2') > -1)) {
    setDisabled(vue, vue.element.tips.socialAssist_eco, false)
  } else {
    setDisabled(vue, vue.element.tips.socialAssist_eco)
  }
  let householdTypeValue = vue.formData.householdType.value
  if (householdTypeValue == '2') {
    setDisabled(vue, vue.element.columns_socialAssist[4])
    deleteArrItems(vue, vue.formData.socialAssist, '5')
    setDisabled(vue, vue.element.tips.socialAssist_hou)
    setDisabled(vue, vue.element.tips.socialAssist_hou_n)
  } else {
    setDisabled(vue, vue.element.columns_socialAssist[4], false)
    let farmHousingValue = vue.formData.farmHousing.value
    if (v.indexOf('5') > -1 && farmHousingValue && farmHousingValue != '1') {
      setDisabled(vue, vue.element.tips.socialAssist_hou, false)
    } else {
      setDisabled(vue, vue.element.tips.socialAssist_hou)
    }
    let historyFarmHousingValue = vue.surveyInfo.historyData.r11
    if (
      v.indexOf('5') < 0 &&
      (historyFarmHousingValue == '2' || historyFarmHousingValue == '3')
    ) {
      setDisabled(vue, vue.element.tips.socialAssist_hou_n, false)
    } else {
      setDisabled(vue, vue.element.tips.socialAssist_hou_n)
    }
  }
}
/**
 * r28.初始化逻辑：社会福利补贴
 * 1.若社会救助勾选了特困供养，则禁用1.困难生活补贴和2.重度护理补贴
 * 2.若社会救助勾选了低保，且未勾选困难生活补贴，提示：勾选了最低生活保障，确认是否享受困难生活补贴
 * 3.若社会救助没有勾选低保，但勾了困难生活补贴，提示：享受了困难生活补贴，但未享受最低生活保障。
 */
function initSocialWelfare (vue) {
  let sv = vue.formData.socialAssist
  if (sv.indexOf('2') > -1) {
    setDisabled(vue, vue.element.columns_socialWelfare.slice(0, 2))
    deleteArrItems(vue, vue.formData.socialWelfare, ['1', '2'])
  } else {
    setDisabled(vue, vue.element.columns_socialWelfare.slice(0, 2), false)
  }
  let v = vue.formData.socialWelfare
  if (sv.indexOf('1') > -1 && v.indexOf('1') < 0) {
    setDisabled(vue, vue.element.tips.socialWelfare_n, false)
  } else {
    setDisabled(vue, vue.element.tips.socialWelfare_n)
  }
  // if (sv.indexOf('1') < 0 && v.indexOf('1') > -1) {
  //   setDisabled(vue, vue.element.tips.socialWelfare_y, false)
  // } else {
  //   setDisabled(vue, vue.element.tips.socialWelfare_y)
  // }
}
/**
 * r29.初始化逻辑：托养
 * 1.年龄在16-59岁间，且为智力或精神或重度肢体，才可以填写
 * 2.若享受重度护理补贴，则选中1.是，禁用2.否
 */
function initFoster (vue) {
  if (!isEnableFoster(vue)) {
    setDisabled(vue, vue.element.modulesValid.foster)
    resetFormData(vue, [vue.formData.foster])
  } else {
    setDisabled(vue, vue.element.modulesValid.foster, false)
    let socialWelfareValue = vue.formData.socialWelfare
    if (socialWelfareValue.indexOf('2') > -1) {
      vue.$set(vue.formData.foster, 'value', '1')
      setDisabled(vue, vue.element.modulesValid.foster_2)
    } else {
      setDisabled(vue, vue.element.modulesValid.foster_2, false)
    }
  }
}
/**
 * r30.初始化逻辑：目前托养服务需求
 * 1.若托养服务选择否，启用，其他情况禁用
 */
function initFosterNeed (vue) {
  let fosterValue = vue.formData.foster.value
  if (!(fosterValue == '2')) {
    setDisabled(vue, vue.element.modulesValid.fosterNeed)
    resetFormData(vue, [vue.formData.fosterNeed])
  } else {
    setDisabled(vue, vue.element.modulesValid.fosterNeed, false)
  }
}
/**
 * r33.初始化逻辑：过去两周是否已就诊或治疗
 * 1.若未患疾病则禁用
 */
function initSickCure (vue) {
  let sickValue = vue.formData.sick.value
  if (!(sickValue == '1')) {
    setDisabled(vue, vue.element.modulesValid.sickCure)
    resetFormData(vue, [vue.formData.sickCure])
  } else {
    setDisabled(vue, vue.element.modulesValid.sickCure, false)
  }
}
/**
 * r34.初始化逻辑：未就诊或治疗原因
 * 1.若过去两周就诊或治疗选择否，启用，其他情况禁用
 */
function initNotCureReason (vue) {
  let sickCureValue = vue.formData.sickCure.value
  if (!(sickCureValue == '2')) {
    setDisabled(vue, vue.element.modulesValid.notCureReason)
    resetFormData(vue, [vue.formData.notCureReason])
  } else {
    setDisabled(vue, vue.element.modulesValid.notCureReason, false)
  }
}

// 初始化康复相关选项
function initHealth (vue) {
  initRehabilitation(vue) // 康复服务
  initNoRehabilitationReason(vue) // 未得到康复服务原因
  initRehabilitationNeed(vue) // 康复服务需求
}

/**
 * r35.初始化逻辑：康复服务
 * 1.若不包含精神残疾，禁用2.药物
 * 2.若不包含视力、听力、肢体，禁用1.手术，禁用4.辅助器具
 * 3.若享受重度护理补贴，选中5.护理，且只读，同时禁用6.未得到
 */
function initRehabilitation (vue) {
  if (dbc.kindstr.indexOf('6') < 0) {
    setDisabled(vue, vue.element.columns_rehabilitation[1])
    deleteArrItems(vue, vue.formData.rehabilitation, '2')
  } else {
    setDisabled(vue, vue.element.columns_rehabilitation[1], false)
  }
  let flag =
    dbc.kindstr.indexOf('1') < 0 &&
    dbc.kindstr.indexOf('2') < 0 &&
    dbc.kindstr.indexOf('4') < 0
  if (flag) {
    setDisabled(vue, vue.element.columns_rehabilitation[0])
    setDisabled(vue, vue.element.columns_rehabilitation[3])
    deleteArrItems(vue, vue.formData.rehabilitation, ['1', '4'])
  } else {
    setDisabled(vue, vue.element.columns_rehabilitation[0], false)
    setDisabled(vue, vue.element.columns_rehabilitation[3], false)
  }
  let socialWelfareValue = vue.formData.socialWelfare
  if (socialWelfareValue.indexOf('2') > -1) {
    if (vue.formData.rehabilitation.indexOf('5') < 0) {
      vue.formData.rehabilitation.push('5')
    }
    vue.$set(vue.element.columns_rehabilitation[4], 'readonly', true)
    setDisabled(vue, vue.element.columns_rehabilitation[5])
    deleteArrItems(vue, vue.formData.rehabilitation, '6')
  } else {
    vue.$set(vue.element.columns_rehabilitation[4], 'readonly', false)
    setDisabled(vue, vue.element.columns_rehabilitation[5], false)
  }
}
/**
 * r36.初始化逻辑：未得到康复服务原因
 * 1.若康复服务为6.未得到，则启用，否则禁用
 */
function initNoRehabilitationReason (vue) {
  let rehabilitation = vue.formData.rehabilitation
  if (!(rehabilitation.indexOf('6') > -1)) {
    setDisabled(vue, vue.element.modulesValid.noRehabilitationReason)
    resetFormData(vue, [vue.formData.noRehabilitationReason])
  } else {
    setDisabled(vue, vue.element.modulesValid.noRehabilitationReason, false)
  }
}
/**
 * r37.初始化逻辑：康复服务需求
 * 1.若不包含精神残疾，禁用2.药物
 * 2.若不包含视力、听力、肢体，禁用1.手术，禁用4.辅助器具
 * 3.若享受重度护理补贴或康复服务包含护理，选中5.护理，且只读，同时禁用6.不需要
 */
function initRehabilitationNeed (vue) {
  if (dbc.kindstr.indexOf('6') < 0) {
    setDisabled(vue, vue.element.columns_rehabilitationNeed[1])
    deleteArrItems(vue, vue.formData.rehabilitationNeed, '2')
  } else {
    setDisabled(vue, vue.element.columns_rehabilitationNeed[1], false)
  }
  let flag =
    dbc.kindstr.indexOf('1') < 0 &&
    dbc.kindstr.indexOf('2') < 0 &&
    dbc.kindstr.indexOf('4') < 0
  if (flag) {
    setDisabled(vue, vue.element.columns_rehabilitationNeed[0])
    setDisabled(vue, vue.element.columns_rehabilitationNeed[3])
    deleteArrItems(vue, vue.formData.rehabilitationNeed, ['1', '4'])
  } else {
    setDisabled(vue, vue.element.columns_rehabilitationNeed[0], false)
    setDisabled(vue, vue.element.columns_rehabilitationNeed[3], false)
  }
  let socialWelfareValue = vue.formData.socialWelfare
  let rehabilitation = vue.formData.rehabilitation
  if (
    socialWelfareValue.indexOf('2') > -1 ||
    rehabilitation.indexOf('5') > -1
  ) {
    if (vue.formData.rehabilitationNeed.indexOf('5') < 0) {
      vue.formData.rehabilitationNeed.push('5')
    }
    //vue.$set(vue.element.columns_rehabilitationNeed[4], 'readonly', true)
    //setDisabled(vue, vue.element.columns_rehabilitationNeed[5])
    deleteArrItems(vue, vue.formData.rehabilitationNeed, '6')
  } else {
    //vue.$set(vue.element.columns_rehabilitationNeed[4], 'readonly', false)
    //setDisabled(vue, vue.element.columns_rehabilitationNeed[5], false)
  }
}
/**
 * r39.初始化逻辑：无障碍改造需求
 * 1.不包含听力，禁用5.闪光门铃；
 * 2.不包含视力，禁用6.煤气报警和7.上网读屏；
 */
function initBarrierFreeNeed (vue) {
  if (dbc.kindstr.indexOf('2') < 0) {
    setDisabled(vue, vue.element.columns_barrierFreeNeed[4])
    deleteArrItems(vue, vue.formData.barrierFreeNeed, '5')
  }
  if (dbc.kindstr.indexOf('1') < 0) {
    setDisabled(vue, vue.element.columns_barrierFreeNeed.slice(5, 7))
    deleteArrItems(vue, vue.formData.barrierFreeNeed, ['6', '7'])
  }
}
// r41.初始化逻辑：文化体育
function initInactivityReason (vue) {
  let activityValue = vue.formData.activity.value
  if (!(activityValue == '2')) {
    setDisabled(vue, vue.element.modulesValid.inactivityReason)
    resetFormData(vue, [vue.formData.inactivityReason])
  } else {
    setDisabled(vue, vue.element.modulesValid.inactivityReason, false)
  }
}
// 检查户主和户主身份证号
/**
 * 1.若户口性质为农业，则户主姓名不能是集体户口
 * 2.若户主姓名为集体户口，则只读，户主身份证号禁填
 * 3.若户主姓名不是集体户口，则不是只读，户主身份证号可以填写
 */
function initHouseholder (vue) {
  let householdTypeValue = vue.formData.householdType.value
  if (householdTypeValue === '1') {
    forbidCollectiveHousehold(vue)
  } else {
    setDisabled(vue, vue.element.modulesValid.collectiveHousehold_1, false)
    if (vue.formData.hostName.value === '集体户口') {
      vue.$set(vue.formData.collectiveHousehold, 'value', '1')
      vue.$set(vue.element.modulesValid.hostName, 'readonly', true)
      setDisabled(vue, vue.element.modulesValid.hostIdentityCard)
      resetFormData(vue, [vue.formData.hostIdentityCard])
    } else {
      vue.$set(vue.element.modulesValid.hostName, 'readonly', false)
      setDisabled(vue, vue.element.modulesValid.hostIdentityCard, false)
    }
  }
  if (!(vue.formData.hostName.value === '集体户口')) {
    vue.$set(vue.formData.collectiveHousehold, 'value', '2')
  }
}
/**
 * 逻辑相关实现函数
 */
// 设置disabled属性
function setDisabled (vue, objArr, bool) {
  if (!objArr) {
    return
  }
  if (bool == null) {
    bool = true // 默认为true
  }
  if (objArr instanceof Array) {
    if (bool instanceof Array) {
      for (let i = 0, len = objArr.length; i < len; i++) {
        vue.$set(objArr[i], 'disabled', bool.length - 1 < i ? true : bool[i])
      }
    } else {
      for (let i = 0, len = objArr.length; i < len; i++) {
        vue.$set(objArr[i], 'disabled', bool)
      }
    }
  } else {
    vue.$set(objArr, 'disabled', bool)
  }
}
// 删除数组中的多个元素
function deleteArrItems (vue, arr, items) {
  if (items instanceof Array) {
    for (let i = 0, len = items.length; i < len; i++) {
      if (arr.indexOf(items[i]) > -1) {
        vue.$delete(arr, arr.indexOf(items[i]))
      }
    }
  } else {
    if (arr.indexOf(items) > -1) {
      vue.$delete(arr, arr.indexOf(items))
    }
  }
}
// 表单元素对象属性重置
function resetFormData (vue, objArr) {
  for (let i = 0, len = objArr.length; i < len; i++) {
    if (objArr[i] instanceof Array) {
      objArr[i].splice(0)
    } else {
      vue.$set(objArr[i], 'text', null)
      vue.$set(objArr[i], 'value', null)
    }
  }
}
// 禁用所有栏目
function disPstate (vue) {
  let modulesValid = vue.element.modulesValid
  // 面板折叠
  deleteArrItems(vue, vue.tab_modules, [
    'baseInfo',
    'economic',
    'education',
    'job',
    'socialSecurity',
    'medical',
    'barrierFree',
    'sports',
    'suppleInfo'
  ])
  // 面板禁用
  setDisabled(
    vue,
    [
      modulesValid.baseInfo,
      modulesValid.economic,
      modulesValid.education,
      modulesValid.job,
      modulesValid.socialSecurity,
      modulesValid.medical,
      modulesValid.barrierFree,
      modulesValid.sports,
      modulesValid.suppleInfo
    ],
    true
  )
}
// 开启所有受残疾人状态影响的栏目
function enablePstate (vue) {
  let bool = isLiveNursing(vue)
  let modulesValid = vue.element.modulesValid
  setDisabled(
    vue,
    [
      modulesValid.baseInfo,
      modulesValid.economic,
      modulesValid.education,
      modulesValid.job,
      modulesValid.socialSecurity,
      modulesValid.medical,
      modulesValid.barrierFree,
      modulesValid.sports,
      modulesValid.suppleInfo
    ],
    [false, bool, false, !isEnableJob(vue), false, false, bool, bool, bool]
  )
}
// 是否居住在养老院
function isLiveNursing (vue) {
  return vue.formData.nursingHouse.value == '1'
}
// 禁用非农业相关选项,启用农业选项
function disNonFarm (vue) {
  let modulesValid = vue.element.modulesValid
  if (!isLiveNursing(vue)) {
    // 在非福利院居住的条件下进行判断
    setDisabled(vue, [modulesValid.nonfarm, modulesValid.farm], [true, false])
    resetFormData(vue, [
      vue.formData.nonfarmEconomy,
      vue.formData.nonfarmHousing
    ])
  }
  setDisabled(vue, vue.element.columns_socialAssist[4], false)
}
// 禁用农业相关选项,启用非农业选项
function disFarm (vue) {
  let modulesValid = vue.element.modulesValid
  if (!isLiveNursing(vue)) {
    // 在非福利院居住的条件下进行判断
    setDisabled(vue, [modulesValid.nonfarm, modulesValid.farm], [false, true])
    resetFormData(vue, [vue.formData.farmEconomy, vue.formData.farmHousing])
  }
  setDisabled(vue, vue.element.columns_socialAssist[4]) // 危房救助（农业）
  deleteArrItems(vue, [vue.formData.socialAssist], '5')
}
// 禁用所有农业和非农业选项
function disAllFarm (vue) {
  let modulesValid = vue.element.modulesValid
  let formData = vue.formData
  setDisabled(vue, [modulesValid.farm, modulesValid.nonfarm])
  resetFormData(vue, [
    formData.farmEconomy,
    formData.farmHousing,
    formData.nonfarmEconomy,
    formData.nonfarmHousing
  ])
  setDisabled(vue, vue.element.columns_socialAssist[4]) // 危房救助（农业）
  deleteArrItems(vue, [formData.socialAssist], '5')
}
// 是否可以填报就业栏目
function isEnableJob (vue) {
  if (dbc.age >= 16 && dbc.age <= 59 && !isLiveNursing(vue)) {
    return true
  } else {
    return false
  }
}
// 禁用在养老院居住不必要的模块
function disNonNursing (vue) {
  disEconomic(vue) // 经济与住房模块禁用并清值
  disJob(vue) // 就业扶贫模块禁用并清值
  disBarrierFree(vue) // 无障碍禁用并清值
  disSports(vue) // 文化体育
  disSuppleInfo(vue) // 补充问题
}
// 解禁在养老院居住禁用掉的模块
function enableNursing (vue) {
  let modulesValid = vue.element.modulesValid
  setDisabled(
    vue,
    [modulesValid.economic, modulesValid.barrierFree, modulesValid.suppleInfo],
    false
  )
  setDisabled(vue, modulesValid.job, !isEnableJob(vue))
  setDisabled(vue, modulesValid.sports, !isEnableSports(vue))
}
// 经济与住房模块禁用并清值
function disEconomic (vue) {
  deleteArrItems(vue, vue.tab_modules, 'economic') // 面板折叠
  setDisabled(vue, vue.element.modulesValid.economic) // 面板禁用
  resetFormData(vue, [
    vue.formData.farmEconomy,
    vue.formData.farmHousing,
    vue.formData.nonfarmEconomy,
    vue.formData.nonfarmHousing
  ])
}
// 就业扶贫模块禁用并清值
function disJob (vue) {
  deleteArrItems(vue, vue.tab_modules, 'job') // 面板折叠
  setDisabled(vue, vue.element.modulesValid.job) // 面板禁用
  resetFormData(vue, [
    vue.formData.employ,
    vue.formData.employType,
    vue.formData.unemployedIncome,
    vue.formData.unemployedReason,
    vue.formData.employAssist,
    vue.formData.employAssistNeed
  ])
  setDisabled(vue, [
    vue.element.tips.unemployedReason,
    vue.element.tips.unemployedIncome
  ])
}
// 无障碍改造模块禁用并清值
function disBarrierFree (vue) {
  deleteArrItems(vue, vue.tab_modules, 'barrierFree') // 面板折叠
  setDisabled(vue, vue.element.modulesValid.barrierFree) // 面板禁用
  resetFormData(vue, [vue.formData.barrierFree, vue.formData.barrierFreeNeed])
}
function isEnableSports (vue) {
  if (!isLiveNursing(vue) && dbc.age >= 6) {
    return true
  } else {
    return false
  }
}
// 文化体育模块禁用并清值
function disSports (vue) {
  deleteArrItems(vue, vue.tab_modules, 'sports') // 面板折叠
  setDisabled(vue, vue.element.modulesValid.sports) // 面板禁用
  resetFormData(vue, [vue.formData.activity, vue.formData.inactivityReason])
}
// 补充问题模块禁用并清值
function disSuppleInfo (vue) {
  deleteArrItems(vue, vue.tab_modules, 'suppleInfo') // 面板折叠
  setDisabled(vue, vue.element.modulesValid.suppleInfo) // 面板禁用
  resetFormData(vue, [
    vue.formData.collectiveHousehold,
    vue.formData.hostName,
    vue.formData.hostIdentityCard
  ])
}
// 禁用因为不识字需要禁用的选项
function disNonLiteracy (vue) {
  disNonLiteracy_education(vue)
  disNonLiteracy_school(vue)
}
// 禁用因为不识字需要禁用的选项:受教育程度
function disNonLiteracy_education (vue) {
  let element = vue.element
  let formData = vue.formData
  setDisabled(vue, element.columns_education, [false, false, false, false])
  if (formData.education.value && parseInt(formData.education.value) > 4) {
    resetFormData(vue, [formData.education])
  }
}
// 禁用因为不识字需要禁用的选项:就读学校
function disNonLiteracy_school (vue) {
  let element = vue.element
  let formData = vue.formData
  setDisabled(vue, element.columns_generalSchool, [
    false,
    false,
    false,
    false,
    false
  ])
  setDisabled(vue, element.columns_specialSchool, [
    false,
    false,
    false,
    false,
    false
  ])
  if (
    formData.generalSchool.value &&
    parseInt(formData.generalSchool.value) > 4
  ) {
    resetFormData(vue, [formData.generalSchool])
  } else if (
    formData.specialSchool.value &&
    parseInt(formData.specialSchool.value) > 10
  ) {
    resetFormData(vue, [formData.specialSchool])
  }
  if (!(vue.formData.generalSchool.value || vue.formData.specialSchool.value)) {
    setDisabled(vue, vue.element.tips.school)
  }
}
// 禁用就读学校
function disSchool (vue) {
  setDisabled(vue, vue.element.modulesValid.school)
  resetFormData(vue, [vue.formData.generalSchool, vue.formData.specialSchool])
  setDisabled(vue, vue.element.tips.school)
}
// 禁用就业扶贫帮扶
function disEmployAssist (vue) {
  resetFormData(vue, [vue.formData.employAssist])
  setDisabled(vue, vue.element.modulesValid.employAssist)
}
// 禁用就业扶贫帮扶需求
function disEmployAssistNeed (vue) {
  resetFormData(vue, [vue.formData.employAssistNeed])
  setDisabled(vue, vue.element.modulesValid.employAssistNeed)
}
// 是否可以填写托养相关选项
function isEnableFoster (vue) {
  let flag1 = dbc.age >= 16 && dbc.age <= 59 // 年龄16-59之间
  var flag2 = dbc.kindstr.indexOf('5') > -1 || dbc.kindstr.indexOf('6') > -1 // 智力或精神
  var flag3 =
    dbc.kindstr.indexOf('4') > -1 &&
    (dbc.bodyLevel == '1' || dbc.bodyLevel == '2')
  return flag1 && (flag2 || flag3)
}
// 禁用集体户口
function forbidCollectiveHousehold (vue) {
  if (vue.formData.hostName.value == '集体户口') {
    resetFormData(vue, [vue.formData.hostName])
  }
  setDisabled(vue, vue.element.modulesValid.collectiveHousehold_1)
  vue.$set(vue.element.modulesValid.hostName, 'readonly', false)
  setDisabled(vue, vue.element.modulesValid.hostIdentityCard, false)
  vue.$set(vue.formData.collectiveHousehold, 'value', '2')
}
// 放开集体户口
function activeCollectiveHousehold (vue) {
  setDisabled(vue, vue.element.modulesValid.collectiveHousehold_1, false)
}
// 提交前：检查采集信息
function checkIsFinished_collectInfo (vue) {
  let formData = vue.formData
  let declarant = formData.declarant.value
  let title = '采集信息'
  if (!declarant) {
    return { title: title, msg: '申报人不能为空' }
  } else if (!regName.test(declarant)) {
    return { title: title, msg: '申报人姓名格式有误' }
  }
  let partner = formData.partner.value
  if (partner && !regName.test(partner)) {
    return { title: title, msg: '陪调员姓名格式有误' }
  }
  return
}
// 提交前：检查基本信息
function checkIsFinished_baseInfo (vue) {
  let title = '基本信息'
  let formData = vue.formData
  let householdTypeValue = formData.householdType.value
  if (!householdTypeValue) {
    return { title: title, msg: 'R3.户口性质不能为空' }
  }
  if (!element.modulesValid.marriage.disabled) {
    let marriageValue = formData.marriage.value
    if (!marriageValue) {
      return { title: title, msg: 'R4.婚姻状况不能为空' }
    }
  }
  if (!element.modulesValid.contactName.disabled) {
    let contactNameValue = formData.contactName.value
    if (!contactNameValue) {
      return { title: title, msg: 'R5.联系人姓名不能为空' }
    } else if (!regName.test(contactNameValue)) {
      return { title: title, msg: 'R5.联系人姓名填写有误' }
    }
  }
  let telephoneValue = formData.telephone.value
  let mobilephoneValue = formData.mobilephone.value
  if (!telephoneValue && !mobilephoneValue) {
    return { title: title, msg: 'R6.固话和手机号至少填写一项' }
  } else {
    let tempMsg = []
    if (telephoneValue && !regTelephone.test(telephoneValue)) {
      tempMsg.push('R6.固话填写有误（格式：区号-号码）')
    }
    if (mobilephoneValue && !regMobilephone.test(mobilephoneValue)) {
      tempMsg.push('R6.手机号码有误')
    }
    if (tempMsg.length > 0) {
      return { title: title, msg: tempMsg.join('\n') }
    }
  }
  let nursingHouseValue = formData.nursingHouse.value
  if (!nursingHouseValue) {
    return {
      title: title,
      msg: 'R7.是否在敬（养）老院、福利院、荣军院等居住不能为空'
    }
  }
}
// 提交前：检查经济及住房
function checkIsFinished_economic (vue) {
  let title = '经济及住房'
  let formData = vue.formData
  if (element.modulesValid.economic.disabled) {
    return
  }
  if (!element.modulesValid.nonfarm.disabled) {
    let nonfarmEconomyValue = formData.nonfarmEconomy.value
    if (!nonfarmEconomyValue) {
      return {
        title: title,
        msg: 'R8.非农业家庭人均收入状况不能为空'
      }
    }
    let nonfarmHousingValue = formData.nonfarmHousing.value
    if (!nonfarmHousingValue) {
      return { title: title, msg: 'R9.非农业家庭住房状况不能为空' }
    }
  }
  if (!element.modulesValid.farm.disabled) {
    let farmEconomyValue = formData.farmEconomy.value
    if (!farmEconomyValue) {
      return {
        title: title,
        msg: 'R10.农业贫困与建档立卡状况不能为空'
      }
    }
    let farmHousingValue = formData.farmHousing.value
    if (!farmHousingValue) {
      return { title: title, msg: 'R11.农业家庭住房状况不能为空' }
    }
  }
}
// 提交前：检查教育
function checkIsFinished_education (vue) {
  let title = '教育'
  let formData = vue.formData
  if (!element.modulesValid.literacy.disabled) {
    if (!formData.literacy.value) {
      return { title: title, msg: 'R12.是否识字不能为空' }
    }
  }
  if (!element.modulesValid.educationLevel.disabled) {
    if (!formData.education.value) {
      return { title: title, msg: 'R13.受教育程度不能为空' }
    }
  }
  if (!element.modulesValid.notEnrolledReason.disabled) {
    if (!formData.notEnrolledReason.value) {
      return { title: title, msg: 'R15.未入学原因不能为空' }
    }
  }
}
// 提交前：检查就业扶贫
function checkIsFinished_job (vue) {
  let title = '就业扶贫'
  let formData = vue.formData
  if (element.modulesValid.job.disabled) {
    return
  }
  if (!formData.employ.value) {
    return { title: title, msg: 'R16.是否就业不能为空' }
  }
  if (!element.modulesValid.employType.disabled) {
    if (!formData.employType.value) {
      return { title: title, msg: 'R17.残疾人就业形式不能为空' }
    }
  }
  if (!element.modulesValid.unemployedIncome.disabled) {
    if (!formData.unemployedIncome.value) {
      return { title: title, msg: 'R18.未就业主要生活来源不能为空' }
    }
  }
  if (!element.modulesValid.unemployedReason.disabled) {
    if (!formData.unemployedReason.value) {
      return { title: title, msg: 'R19.未就业主要原因不能为空' }
    }
  }
  if (!element.modulesValid.employAssist.disabled) {
    if (formData.employAssist.length == 0) {
      return {
        title: title,
        msg: 'R20.动态更新年度内的就业扶贫帮扶不能为空'
      }
    }
  }
  if (!element.modulesValid.employAssistNeed.disabled) {
    let employAssistNeed = formData.employAssistNeed
    if (employAssistNeed.length == 0) {
      return { title: title, msg: 'R21.目前就业扶贫需求不能为空' }
    }
  }
}
// 提交前：检查社会保障
function checkIsFinished_socialSecurity (vue) {
  let title = '社会保障'
  let formData = vue.formData
  if (!element.modulesValid.socialInsurance.disabled) {
    if (formData.socialInsurance.length == 0) {
      return {
        title: title,
        msg: 'R22.是否参加职工社会保险不能为空'
      }
    }
  }
  if (!element.modulesValid.endowmentInsurance.disabled) {
    if (!formData.endowmentInsurance.value) {
      return {
        title: title,
        msg: 'R23.是否参加城乡居民养老保险不能为空'
      }
    }
  }
  if (!element.modulesValid.endowmentSubsidy.disabled) {
    if (!formData.endowmentSubsidy.value) {
      return {
        title: title,
        msg: 'R24.是否享受居民养老保险缴费补贴不能为空'
      }
    }
  }
  if (!formData.medicalInsurance.value) {
    return {
      title: title,
      msg: 'R25.是否参加医疗保险(城镇居民/新农合)不能为空'
    }
  }
  if (!element.modulesValid.medicalSubsidy.disabled) {
    if (!formData.medicalSubsidy.value) {
      return {
        title: title,
        msg: 'R26.是否享受医疗保险缴费补贴不能为空'
      }
    }
  }
  if (formData.socialAssist.length == 0) {
    return {
      title: title,
      msg: 'R27.动态更新年度内社会救助情况不能为空'
    }
  }
  if (formData.socialWelfare.length == 0) {
    return {
      title: title,
      msg: 'R28.动态更新年度内社会福利补贴情况不能为空'
    }
  }
  if (!element.modulesValid.foster.disabled) {
    if (!formData.foster.value) {
      return {
        title: title,
        msg: 'R29.是否享受托养服务不能为空'
      }
    }
  }
  if (!element.modulesValid.fosterNeed.disabled) {
    if (!formData.fosterNeed.value) {
      return { title: title, msg: 'R30.目前托养需求不能为空' }
    }
  }
}
// 提交前：检查基本医疗与康复
function checkIsFinished_medical (vue) {
  let title = '基本医疗与康复'
  let formData = vue.formData
  if (!formData.familyDoctor.value) {
    return {
      title: title,
      msg: 'R31.个人或家庭是否签订家庭医生服务协议不能为空'
    }
  }
  if (!formData.sick.value) {
    return {
      title: title,
      msg: 'R32.除残疾外，过去两周是否患有其他疾病不能为空'
    }
  }
  if (!element.modulesValid.sickCure.disabled) {
    if (!formData.sickCure.value) {
      return { title: title, msg: 'R33.过去两周内是否已就诊或治疗不能为空' }
    }
  }
  if (!element.modulesValid.notCureReason.disabled) {
    if (formData.notCureReason.length == 0) {
      return { title: title, msg: 'R34.未就诊或治疗原因不能为空' }
    }
  }
  if (formData.rehabilitation.length == 0) {
    return {
      title: title,
      msg: 'R35.针对自身残疾，动态年度内是否得到或使用过康复服务不能为空'
    }
  }
  if (!element.modulesValid.noRehabilitationReason.disabled) {
    if (formData.noRehabilitationReason.length == 0) {
      return { title: title, msg: 'R36.未得到康复服务的原因不能为空' }
    }
  }
  if (formData.rehabilitationNeed.length == 0) {
    return {
      title: title,
      msg: 'R37.针对自身残疾，目前是否还需要以下服务不能为空'
    }
  }
}
// 提交前：检查无障碍改造模块
function checkIsFinished_barrierFree (vue) {
  let title = '无障碍改造'
  let formData = vue.formData
  if (element.modulesValid.barrierFree.disabled) {
    return
  }
  if (!formData.barrierFree.value) {
    return {
      title: title,
      msg: 'R38.动态年度内你家是否进行过无障碍改造不能为空'
    }
  }
  if (formData.barrierFreeNeed.length == 0) {
    return {
      title: title,
      msg: 'R39.目前你家有哪些无障碍改造需求不能为空'
    }
  }
}
// 提交前：检查文化体育模块
function checkIsFinished_sports (vue) {
  let title = '文化体育'
  let formData = vue.formData
  if (element.modulesValid.sports.disabled) {
    return
  }
  if (!formData.activity.value) {
    return {
      title: title,
      msg: 'R40.动态年度内是否经常参加村（社区）组织的文化体育活动不能为空'
    }
  }
  if (!element.modulesValid.inactivityReason.disabled) {
    if (formData.inactivityReason.length == 0) {
      return {
        title: title,
        msg: 'R41.不能参加村（社区）组织的文化体育活动的原因不能为空'
      }
    }
  }
}
// 提交前：检查补充问题
function checkIsFinished_suppleInfo (vue) {
  let title = '补充问题'
  let formData = vue.formData
  if (element.modulesValid.suppleInfo.disabled) {
    return
  }
  if (!formData.collectiveHousehold.value) {
    return {
      title: title,
      msg: '是否为集体户口为必填项'
    }
  }
  if (!formData.hostName.value) {
    return {
      title: title,
      msg: '户主姓名不能为空'
    }
  } else if (!regName.test(formData.hostName.value)) {
    return {
      title: title,
      msg: '户主姓名填写不正确'
    }
  }

  if (!element.modulesValid.hostIdentityCard.disabled) {
    if (!formData.hostIdentityCard.value) {
      return {
        title: title,
        msg: '户主身份证号不能为空'
      }
    } else if (checkIdcard(formData.hostIdentityCard.value)) {
      return {
        title: title,
        msg: '户主身份证号填写有误'
      }
    }
  }
}
// 提交前：检查入户调查照片
function checkImg (vue) {
  let title = '入户调查照片'
  let formData = vue.formData
  if (formData.dtype.value == '2') {
    return
  }
  if (formData.fileList.length == 0) {
    return {
      title: title,
      msg: '上门采集，须上传入户调查照片'
    }
  }
}
// 检查正常提交需要验证的表单
function checkIsFinished (vue) {
  let result
  let flag = true
  // 基本信息
  result = result || checkIsFinished_baseInfo(vue)
  if (result && flag) {
    vue.tab_modules = 'baseInfo'
    flag = false
  }
  // 经济及住房
  result = result || checkIsFinished_economic(vue)
  if (result && flag) {
    vue.tab_modules = 'economic'
    flag = false
  }
  // 教育
  result = result || checkIsFinished_education(vue)
  if (result && flag) {
    vue.tab_modules = 'education'
    flag = false
  }
  // 就业扶贫
  result = result || checkIsFinished_job(vue)
  if (result && flag) {
    vue.tab_modules = 'job'
    flag = false
  }
  // 社会保障
  result = result || checkIsFinished_socialSecurity(vue)
  if (result && flag) {
    vue.tab_modules = 'socialSecurity'
    flag = false
  }
  // 基本医疗与康复
  result = result || checkIsFinished_medical(vue)
  if (result && flag) {
    vue.tab_modules = 'medical'
    flag = false
  }
  // 无障碍改造
  result = result || checkIsFinished_barrierFree(vue)
  if (result && flag) {
    vue.tab_modules = 'barrierFree'
    flag = false
  }
  // 文化体育
  result = result || checkIsFinished_sports(vue)
  if (result && flag) {
    vue.tab_modules = 'sports'
    flag = false
  }
  // 补充问题
  result = result || checkIsFinished_suppleInfo(vue)
  if (result && flag) {
    vue.tab_modules = 'suppleInfo'
    flag = false
  }
  //上门采集照片
  //result = result || checkImg(vue)
  return result
}

export default {
  setDisabled,
  resetFormData,
  initData, // 初始化表单方法
  initLogic, // 初始化逻辑
  initEconomic, // 初始化逻辑：经济与住房
  initJob, // 初始化逻辑：就业扶贫模块
  initSocialSecurity, // 初始化逻辑：社会保障模块
  initHealth, // 初始化逻辑：康复相关
  initDisableState, // 残疾人情况
  initMarriage, // r4.婚姻状况
  initContactName, // r5.联系人姓名
  initNonFarmEconomy, // r8.非家庭人均收入状况
  initNonFarmHousing, // r9.非家庭住房状况
  initFarmEconomy, // r10.农业贫困与建档立卡状况
  initFarmHousing, // r11.农业家庭住房状况
  initLiteracy, // r12.是否识字
  initEducation, // r13.受教育程度
  initSchool, // r14.就读学校
  initNotEnrolledReason, // r15.未入学原因
  initEmploy, // r16.是否就业
  initEmployType, // r17.残疾人就业形式
  initUnemployedIncome, // r18.未就业主要生活来源
  initUnemployedReason, // r19.未就业主要原因
  initEmployAssist, // r20.就业帮扶
  initEmployAssistNeed, // r21.就业帮扶需求
  initSocialInsurance, // 社会职工保险逻辑
  initEndowmentInsurance, // 社会居民养老保险
  initEndowmentSubsidy, // 居民养老保险补贴
  initMedicalInsurance, // 居民医疗保险,
  initMedicalSubsidy, // r26.居民医疗保险补贴
  initSocialAssist, // r27.社会救助
  initSocialWelfare, // r28.社会福利补贴
  initFoster, // r29.是否托养服务
  initFosterNeed, // r30.托养服务需求
  initSickCure, // r33.过去两周是否已就诊或治疗
  initNotCureReason, // r34.未就诊或治疗原因
  initRehabilitation, // r35.康复服务
  initNoRehabilitationReason, // r36.未得到康复服务的原因
  initRehabilitationNeed, // r37.康复服务需求
  initBarrierFreeNeed, // r38.无障碍改造需求
  initInactivityReason, // r40.不经常参加文化体育活动的原因
  initHouseholder, // 初始化户口性质
  deleteArrItems,
  disPstate, // 禁用所有受残疾人状态影响的栏目
  enablePstate, // 启用所有受残疾人状态影响的栏目
  disNonNursing, // 禁用在养老院居住不必填写的模块
  enableNursing, // 允许填写被养老院居住影响的模块
  isLiveNursing, // 是否在养老院居住
  disNonFarm,
  disFarm,
  disAllFarm,
  isEnableJob, // 是否允许填写就业栏目
  isEnableSports, // 是否允许填写文化体育
  disNonLiteracy, // 禁用因为不识字需要禁用的选项
  forbidCollectiveHousehold, // 禁止填写集体户口
  activeCollectiveHousehold, // 激活可以填写集体户口
  checkIsFinished_collectInfo,
  checkIsFinished
}
